﻿
Namespace Blog

    Public Class BlogUtils

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="strUrl"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function GetBlogByUrl(ByVal strUrl As String) As Blog

            Dim objBlog As BlogSpark.Blog.Blog
            Dim dt As DataTable = BlogSpark.DataProvider.SPs.GetBlogByUrl(BlogSpark.DataProvider.Data.ConnectionType, strUrl).Tables(0)

            If dt.Rows.Count > 0 Then
                objBlog = New BlogSpark.Blog.Blog
                objBlog.Fill(dt.Rows(0))

                Return objBlog
            Else
                Return Nothing
            End If

        End Function

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <param name="intBlogId"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function GetBlogById(ByVal intBlogId As Integer) As Blog

            Dim objBlog As BlogSpark.Blog.Blog
            Dim dt As DataTable = BlogSpark.DataProvider.SPs.GetBlogById(BlogSpark.DataProvider.Data.ConnectionType, intBlogId).Tables(0)

            If dt.Rows.Count > 0 Then
                objBlog = New BlogSpark.Blog.Blog
                objBlog.Fill(dt.Rows(0))

                Return objBlog
            Else
                Return Nothing
            End If

        End Function

        Public Shared Function GetBlogsByUserId(ByVal intUserId As Integer) As Blog()

            Dim dt As DataTable = BlogSpark.DataProvider.SPs.GetBlogsByUserId(BlogSpark.DataProvider.Data.ConnectionType, intUserId).Tables(0)
            Dim i As Short = 0

            Dim objBlogs(dt.Rows.Count - 1) As Blog
            For Each dr As DataRow In dt.Select

                objBlogs(i) = New BlogSpark.Blog.Blog
                objBlogs(i).Fill(dt.Rows(i))
                i += 1

            Next

            Return objBlogs

        End Function

    End Class

End Namespace

